home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1997 / MacHack 1997.toast / Hacks / Hacks ’93 / Hellcats FlightRecorder / SaveFrame.c < prev    next >
C/C++ Source or Header  |  1993-06-18  |  2KB  |  88 lines

  1. #include "FlightRecorder.h"
  2.  
  3. Boolean    IsPressed(unsigned short k, unsigned char km[16])
  4. {
  5.     return ((km[k>>3] >> (k & 7)) & 1);
  6. }
  7.  
  8. //
  9. // save one frame of animation out to the PICS movie file
  10. //
  11. void SaveAFrame(storage    *s)
  12. {
  13.     unsigned char keys[16];
  14.  
  15.     GetKeys((void*)keys);
  16.  
  17.     if(IsPressed(0x31,keys)) {
  18.         /* unpatch get next event */
  19.         SetToolTrapAddress( s->gneLink, _GetNextEvent);
  20.         HPurge(s->code);
  21.         CloseResFile(s->ref);
  22.  
  23.     } else {
  24.  
  25.         PicHandle    pict;
  26.         WindowPtr    fWind;
  27.         GrafPtr        savePort;
  28.         short        saveRef;
  29.         OSErr        err;
  30.         
  31.         GetPort(&savePort);
  32.         
  33.         fWind = FrontWindow();
  34.         if(!fWind) return;
  35.         
  36.         /* make sure the window is the current port */
  37.         SetPort(fWind);        
  38.  
  39.         pict = OpenPicture(&fWind->portRect);        
  40.         
  41.         /* copy the window onto itself to record it */
  42.         /* no drawing actually occurs since O.P. calls hide pen */
  43.         CopyBits( &fWind->portBits, 
  44.                     &fWind->portBits,
  45.                     &fWind->portRect,
  46.                     &fWind->portRect,
  47.                     srcCopy,
  48.                     nil);
  49.                          
  50.         ClosePicture();
  51.  
  52.         if( !(**pict).picSize ) {
  53.             DebugStr("\p Picture is messed up");
  54.         }
  55.         
  56.  
  57.         SetPort(savePort);
  58.  
  59.         /* save resource chain */
  60.         saveRef = CurResFile();
  61.         
  62.         /* make our PICS file first */
  63.         UseResFile(s->ref);
  64.         
  65.         /* add our resource to it */
  66.         AddResource( (Handle)pict, 'PICT', s->fCount, "\p");
  67.         if(err = ResError()) {
  68.             DebugStr("\p AddResource failed");
  69.         }
  70.         
  71.         WriteResource( (Handle)pict );
  72.         if(err = ResError()) {
  73.             DebugStr("\p WriteResource failed");
  74.         }
  75.         ReleaseResource( (Handle)pict );
  76.         if(err = ResError()) {
  77.             DebugStr("\p RelaseResource failed");
  78.         }
  79.         UpdateResFile(s->ref);
  80.         
  81.         /* restore resource chain */
  82.         UseResFile(saveRef);
  83.  
  84.         s->fCount++;
  85.  
  86.     }
  87. }
  88.